﻿using System;
using System.Collections.Generic;
using System.Linq;
using Mvcmediaplayer.Models;

namespace Mvcmediaplayer.Helpers
{
    public class PageList : List<Video>
    {
        public int PageIndex { get; private set; }

        public int PageSize { get; private set; }

        public int TotalCount { get; private set; }

        public int TotalPages { get; private set; }

        public PageList(int pageIndex, int pageSize)
        {
             mediaEntities mediaDB = new mediaEntities();
             var videos = mediaDB.Videos;
            PageIndex = pageIndex;
            PageSize = pageSize;
            TotalCount = videos.Count();
            TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize);

            this.AddRange(videos.OrderBy(v => v.Id).Skip(pageIndex * PageSize).Take(PageSize));

        }

        public bool HasPreviousPage 
        {
            get
            {
                return (PageIndex > 0);
            }
        }

        public bool HasNextPage
        {
            get 
            {
                return (PageIndex + 1 < TotalPages);
            }
        }
    }
}